package com.cfswt.tasksystem.controller;

import com.cfswt.tasksystem.mapper.ReminderMapper;
import com.cfswt.tasksystem.mapper.UserMapper;
import com.cfswt.tasksystem.response.JsonResult;
import com.cfswt.tasksystem.security.CustomUserDetails;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reminder")
@Api(tags = "12.消息模块")
public class ReminderController {
    @Autowired
    private ReminderMapper reminderMapper;
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/count/")
    public JsonResult selectReminderCountByUserId(@AuthenticationPrincipal CustomUserDetails userDetails) {
        Integer userId = userMapper.selectIdByNickName(userDetails.getNickName());
        int count = reminderMapper.selectReminderCountByUserId(userId);
        return JsonResult.ok(count);
    }
    @PostMapping("/seen/{reminderId}")
    public JsonResult updateReminderStatus(@PathVariable Integer reminderId){
        reminderMapper.updateReminderStatusById(reminderId);
        return JsonResult.ok();
    }

}
